<?php
!function_exists('adminmsg') && exit('Forbidden');
InitGP(array('hid'),'2');
empty($hid) && adminmsg('undefined_action');
InitGP(array('type'));

$_basename	= $basename.'&action=album&hid='.$hid;
$imageTypeService = House::loadClass('houseimagetype'); /* @var $imageTypeService PW_HouseImageType */
$topTypes = $imageTypeService->getTopTypes();
$secendTypes = $imageTypeService->getSecendTypes();
$imageService = House::loadClass('houseimage'); /* @var $imageService PW_HouseImage */
if (!$type) {
	InitGP(array('typeid','page'),'',2);
	!$page && $page =1;
	$images = $imageService->getImages($hid,$typeid,$page);
	$pages = $imageService->getPages($hid,$typeid,$page,$_basename.'&typeid='.$typeid.'&');
	$ajax_basename = EncodeUrl($_basename);
	require_once PrintMode('album');
} elseif ($type=='upload') {
	InitGP(array('step','typeid'),'',2);
	if ($step==2) {
		$imageService->addImages($hid,$typeid,$admin_name);
		adminmsg('operate_success',$_basename);
	} else {
		$uid = $db->get_value("SELECT uid FROM pw_members WHERE username=".pwEscape($admin_name));
		$swfhash = GetVerifyForFlash($uid);
		require_once PrintMode('album');
	}
} elseif ($type=='editimage') {
	define('AJAX', 1);
	InitGP(array('step','id'));
	if ($step == 2) {
		InitGP(array('typeid','descrip'));
		$imageService->updateImage($id,array('typeid'=>$typeid,'descrip'=>$descrip));
		$imageType = $imageTypeService->getType($typeid);
		echo "success|".$imageType['name']."|".$descrip;
	} else {
		$ajax_basename = EncodeUrl($_basename);
		$image = $imageService->getImage($id);
		require_once PrintMode('ajax_image');
	}
	ajax_footer();
} elseif ($type=='deleteimage') {
	define('AJAX', 1);
	InitGP(array('id'));
	$imageService->deleteImage($id);
	echo 'success';
	ajax_footer();
} elseif ($type=='deleteimages') {
	InitGP(array('select'));
	if (!$select) {
		adminmsg('请选择要删除的图片',$_basename);
	}
	$imageService->deleteImages($select);
	adminmsg('operate_success',$_basename);
}

function GetVerifyForFlash($str,$app = null) {
	empty($app) && $app = $GLOBALS['db_siteid'];
	return substr(md5($str.$app.$GLOBALS['pwServer']['HTTP_USER_AGENT']),8,8);
}
?>